package br.ufal.ic.fracao.especialist.facade;

import br.ufal.ic.fracao.especialist.domain.Item;
import br.ufal.ic.fracao.especialist.domain.Rule;
import br.ufal.ic.fracao.especialist.inference.InferenceAlgorithm;
import br.ufal.ic.fracao.especialist.infra.Persistence;
import java.io.IOException;
import java.util.List;
import org.jdom.JDOMException;

public class Fachada {
    private static Fachada fachada;
    
    private Persistence p;
    private InferenceAlgorithm inf;
    static {
        fachada = new Fachada();
    }
    
    public static Fachada getInstance() {
        return fachada;
    }
    
   
    private Fachada() {
        p = new Persistence();
        inf = new InferenceAlgorithm();
    }
    
    public void addRule(List<Rule> listRule) throws IOException, JDOMException{
        for(Rule _rule : listRule){
            p.insertRule(_rule);
        }
    }
    
    public List<Rule> getRules() throws IOException, JDOMException{
        return p.getRules();
        
    }
    
    public void addMemory(Item i) throws IOException, JDOMException{
        
        inf.addToMemoryWorking(i);
    }
    
    public void inferirBackwardChaining(boolean explanationMode) throws IOException, JDOMException{
        
        inf.doBackwardChaining(explanationMode);
    }
    
    public void inferirForwardChaining(Item _item, boolean explanationMode) throws IOException, JDOMException{
        
        inf.doForwardChaining(_item, explanationMode);       
    }
    
    public List<String> getConclusions() throws IOException, JDOMException{
        
        return inf.getConclusions();
    
    }
    
    public void removeRules() throws JDOMException, IOException{
        
        p.removeRules();
        
    }
}
